package com.duoec.doc.service.impl.mock.operator;

import com.duoec.doc.helper.NumberHelper;
import org.springframework.stereotype.Service;

/**
 * >=
 *
 * @author xuwenzhen
 * @date 2020/2/7
 */
@Service
public class GteMockOperator implements MockOperator {

    /**
     * 检查{value}是否匹配{checkValue},比如 {value} > {checkValue}
     *
     * @param value      请求里的值
     * @param checkValue 期望的值
     * @return 是否符合当前运算符预期
     */
    @Override
    public boolean match(String value, String checkValue) {
        if (NumberHelper.isNumeric(value) && NumberHelper.isNumeric(checkValue)) {
            //如果两个都是数值，则进行数值比较
            return Double.parseDouble(value) >= Double.parseDouble(checkValue);
        }
        //否则进行字符串比较
        return value.compareTo(checkValue) >= 0;
    }

    /**
     * 获取操作符
     *
     * @return 操作符
     * @demo ==
     */
    @Override
    public String getOperator() {
        return ">=";
    }
}
